const Redis = require('ioredis');

const port = 6379;
const host = '127.0.0.1';

const redis = new Redis(port, host);

(async () => {
    // 开启事务
    const multi = redis.multi();

    multi.del('nickname');
    multi.set('nickname', '张三丰');
    multi.get('nickname', (error, value) => {
        console.log(error, value);
    });

    multi.del('monkeys');
    multi.zadd('monkeys', 1, '孙悟空');
    multi.zadd('monkeys', 2, '孙行者');
    multi.zadd('monkeys', 3, '者行孙');
    //const pipeline = multi.zrangebyscore( 'monkeys' , 1 , 3 );
    //console.log( pipeline );

    // 执行事务
    multi.exec();

    let result = await redis.zrangebyscore('monkeys', 1, 3);
    console.log(result);
})();
